package com.cloud.fim.gate.handler;

import com.cloud.fim.common.Msg;
import com.cloud.fim.common.msg.AuthRequestMsg;
import com.cloud.fim.common.process.AbstractIMProcessor;
import com.cloud.fim.gate.bean.ServerService;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 */
@Slf4j
@Component
@ChannelHandler.Sharable
public class LoginHandler extends SimpleChannelInboundHandler<Msg> {

    @Autowired
    private ServerService service;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        // 注册信息
        super.channelActive(ctx);
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Msg msg) throws Exception {
         // 处理登录
    }
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {

    }

    class MsgProcessor extends AbstractIMProcessor<Class<? extends Msg>,ChannelHandlerContext,Msg> {
        @Override
        public void registryProcessor() {
            registry(AuthRequestMsg.class, (ctx, msg) -> service.auth(ctx, msg));
        }

    }


}
